package practice.library.webmagic.processor_test

import us.codecraft.webmagic.processor.PageProcessor
import us.codecraft.webmagic.{Page, Site}
import utility.CustomLogger

/**
  * Created by lovepocky(lovepocky@foxmail.com) on 2016/6/16.
  */
class RomeOfQyerPageProcessorTest extends PageProcessor with CustomLogger {
	val site = Site.me().setRetryTimes(5).setSleepTime(1000)
	
	override def getSite: Site = site
	
	override def process(page: Page): Unit = {
		//Handle Current Page
		loggers.console.info(page.getUrl.toString)
		
		if (page.getUrl.toString.matches("http://place.qyer.com/\\w+/")) {
			//page.putField("type", page.getHtml.css("head > meta:nth-child(10)"))
			page.putField("keywords", page.getHtml.css("meta[name=\"keywords\"]", "content"))
			page.putField("image_url", page.getHtml.css("meta[property=\"og:image\"]", "content"))
			page.putField("name_chs", page.getHtml.css("body > div.plcTopBar.clearfix > div.plcTopBarL > div > p > a", "text").replace(" ", ""))
			page.putField("name_en", page.getHtml.css("body > div.plcTopBar.clearfix > div.plcTopBarL > p > a", "text").replace(" ", ""))
		}
		
		loggers.console.info(page.getResultItems.toString)
		
		//Add New Page URL
		
	}
}
